From 5214c4f07397c891564eb85ea3e8396e0fe127a0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 2 Nov 2011 20:01:22 +0000 Subject: [PATCH] * Let HTMLFileCache constructor take in a Title *or* a the prefixed dbkey itself. * Tweaked filecache fallback in fileCachedPage() to try the raw title param. If the DB is down, we can get most views of titles with colons in them to work this way. Previously, it could fail on an interwiki lookup. --- includes/cache/HTMLFileCache.php | 8 +++++--- includes/db/DatabaseError.php | 15 +++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index c0c4a577f8..671b15002a 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -7,18 +7,20 @@ class HTMLFileCache extends FileCacheBase { /** * Construct an ObjectFileCache from a Title and an action - * @param $title Title + * @param $title Title|string Title object or prefixed DB key string * @param $action string * @return HTMLFileCache */ - public static function newFromTitle( Title $title, $action ) { + public static function newFromTitle( $title, $action ) { $cache = new self(); $allowedTypes = self::cacheablePageActions(); if ( !in_array( $action, $allowedTypes ) ) { throw new MWException( "Invalid filecache type given." ); } - $cache->mKey = $title->getPrefixedDBkey(); + $cache->mKey = ( $title instanceof Title ) + ? $title->getPrefixedDBkey() + : (string)$title; $cache->mType = (string)$action; $cache->mExt = 'html'; diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index acf97b98f0..d7bfe93312 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -220,16 +220,23 @@ EOT; * @return string */ private function fileCachedPage() { - global $wgTitle, $wgOut; + global $wgTitle, $wgOut, $wgRequest; if ( $wgOut->isDisabled() ) { return; // Done already? } - if ( $wgTitle ) { - $t =& $wgTitle; + if ( $wgTitle ) { // use $wgTitle if we managed to set it + $t = $wgTitle->getPrefixedDBkey(); } else { - $t = Title::newFromText( $this->msg( 'mainpage', 'Main Page' ) ); + # Fallback to the raw title URL param. We can't use the Title + # class is it may hit the interwiki table and give a DB error. + # We may get a cache miss due to not sanitizing the title though. + $t = str_replace( ' ', '_', $wgRequest->getVal( 'title' ) ); + if ( $t == '' ) { // fallback to main page + $t = Title::newFromText( + $this->msg( 'mainpage', 'Main Page' ) )->getPrefixedDBkey(); + } } $cache = HTMLFileCache::newFromTitle( $t, 'view' ); -- 2.20.1